Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-custom

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-custom

Custom authentication strategy for Passport.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
234K
increased by7.87%
Maintainers
1
Weekly downloads
 
Created

What is passport-custom?

The passport-custom npm package allows you to create custom authentication strategies for Passport.js. This is useful when you need to implement authentication mechanisms that are not covered by the existing Passport.js strategies.

What are passport-custom's main functionalities?

Custom Authentication Strategy

This feature allows you to define a custom authentication strategy. In this example, the strategy checks for a user in the database and verifies the password.

const passport = require('passport');
const CustomStrategy = require('passport-custom').Strategy;

passport.use('custom', new CustomStrategy(
  function(req, done) {
    User.findOne({ username: req.body.username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (!user.verifyPassword(req.body.password)) { return done(null, false); }
      return done(null, user);
    });
  }
));

Integration with Express

This feature demonstrates how to integrate the custom authentication strategy with an Express application. The '/login' route uses the custom strategy for authentication.

const express = require('express');
const passport = require('passport');
const bodyParser = require('body-parser');

const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());

app.post('/login',
  passport.authenticate('custom', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
  });

Other packages similar to passport-custom

Keywords

FAQs

Package last updated on 12 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc